<?php

namespace App\Http\Controllers\Member;

use App\Models\Category;
use App\Models\CompanyProfile;
use App\Http\Controllers\Core\HomeController as Home;
use App\Models\JobResumeAccess;
use App\Models\Member;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;

class JobController extends Home
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function apply()
    {
        if (!$this->isLogin()) {
            return redirect('login');
        }
        if ($this->member->type != 2) {
            return redirect('login');
        }
        // TODO 分类信息后期做缓存
        $category = Category::category_cache();
        //获取用户信息
        $member = $this->member;
        $job = JobResumeAccess::select("job_resume_access.id","job_resume_access.job_id", "jobs.company_cn", "jobs.jobs_name", "jobs.jobs_name", "job_resume_access.status", "job_resume_access.create_time")->join('jobs', 'job_resume_access.job_id', '=', 'jobs.id')->where(['job_resume_access.user_id' => $this->member->id, 'member_status' => 1])->paginate(10);
        return view('member.job.index', ['category' => $category, 'member' => $member, 'job' => $job]);
    }

    public function interview()
    {
        if (!$this->isLogin()) {
            return redirect('login');
        }
        if ($this->member->type != 2) {
            return redirect('login');
        }
        //获取面试邀请
        $job = JobResumeAccess::select("job_resume_access.id", "job_resume_access.job_id", "jobs.company_cn", "jobs.jobs_name", "jobs.jobs_name", "job_resume_access.status", "job_resume_access.create_time")->join('jobs', 'job_resume_access.job_id', '=', 'jobs.id')->where(['job_resume_access.user_id' => $this->member->id, 'member_status' => 1])->where(function ($query) {
            $query->where(['job_resume_access.status' => 3])->orWhere(['job_resume_access.status' => 4]);
        })->paginate(10);
        return view('member.job.interview', ['job' => $job]);
    }

    public function favorite()
    {
        if (!$this->isLogin()) {
            return redirect('login');
        }
        if ($this->member->type != 2) {
            return redirect('login');
        }
        return view('member.job.favorite');
    }
}